package test;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class StringFormatFactory extends BasePooledObjectFactory<StringFormat> {

	@Override
	public StringFormat create() {
		System.out.println("create object");
		return new StringFormat();
	}

	/**
	 * Use the default PooledObject implementation.
	 */
	@Override
	public PooledObject<StringFormat> wrap(StringFormat buffer) {
		return new DefaultPooledObject<StringFormat>(buffer);
	}

	/**
	 * When an object is returned to the pool, clear the buffer.
	 */
	@Override
	public void passivateObject(PooledObject<StringFormat> pooledObject) {
		System.out.println("Object been returned to pool");
	}

	// for all other methods, the no-op implementation
	// in BasePooledObjectFactory will suffice
}
